package org.cbg.btn;

import java.awt.Color;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.net.URI;

import javax.swing.SwingConstants;

import com.tool.imagemonitor.PlayerMonitor;
import org.cbg.panel.TraslationCommodityMainJPane;
import org.come.Frame.FriendChatMessageJframe;
import org.come.Frame.OptionsJframe;
import org.come.Frame.ZhuFrame;
import org.come.entity.Friendtable;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;

import com.tool.btn.MoBanBtn;

import come.tool.JDialog.TiShiUtil;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.UserMessUntil;

public class CBGLijigoumaiBtn extends MoBanBtn {

    private TraslationCommodityMainJPane traslationCommodityMainJPane;

    // public CBGLijigoumaiBtn(String iconpath, int type, String text,
    // TraslationCommodityMainJPane traslationCommodityMainJPane) {
    // super(iconpath, type);
    // // TODO Auto-generated constructor stub
    // this.setText(text);
    // setFont(UIUtils.TEXT_FONT1);
    // setForeground(UIUtils.getColor("yellow"));
    // setVerticalTextPosition(SwingConstants.CENTER);
    // setHorizontalTextPosition(SwingConstants.CENTER);
    // this.traslationCommodityMainJPane = traslationCommodityMainJPane;
    // }

    public CBGLijigoumaiBtn(String iconpath, int type, Color[] colors, Font font, String text,
            TraslationCommodityMainJPane traslationCommodityMainJPane) {
        super(iconpath, type, colors);
        // TODO Auto-generated constructor stub
        this.setText(text);
        setFont(font);
        setVerticalTextPosition(SwingConstants.CENTER);
        setHorizontalTextPosition(SwingConstants.CENTER);
        this.traslationCommodityMainJPane = traslationCommodityMainJPane;
    }



    @Override
    public void chooseyes() {
        // TODO Auto-generated method stub

    }

    @Override
    public void chooseno() {
        // TODO Auto-generated method stub

    }

    @Override
    public void nochoose(MouseEvent e) {
        // TODO Auto-generated method stub

        // TODO Auto-generated method stub
        Desktop desktop = Desktop.getDesktop();
        if("联系卖家".equals(this.getText())){
            //添加好友
            PlayerMonitor.addFriend(new BigDecimal(traslationCommodityMainJPane.getSellerID().getText()), traslationCommodityMainJPane.getNickname().getText());

            new Thread(() -> {
                try {
                    Thread.sleep(500L);
                } catch (InterruptedException ee) {
                    ee.printStackTrace();
                }
                for(int i = 0; i < UserMessUntil.getFriendtables().size(); ++i) {
                    Friendtable friend = (Friendtable)UserMessUntil.getFriendtables().get(i);
                    if (friend.getRolename().equals(traslationCommodityMainJPane.getNickname().getText())) {
                        FriendChatMessageJframe.getFriendChatMessageJframe().getJpanel().showFriend(friend, MessagrFlagUntil.getRichLabel(friend.getRolename()));
                        FormsManagement.showForm(56);
                        return;
                    }
                }
            }).start();
        }else {

            // 判断是否是公示期的物品
            int type = 1;
            if (traslationCommodityMainJPane.getIncreaseAmount().isVisible()) {
                type = 1;
                if ("1".equals(traslationCommodityMainJPane.getGouxuan().getName())) {
                    ZhuFrame.getZhuJpanel().addPrompt2("所选物品还在公示期请先勾选确认");
                    return;
                }
            } else {
                type = 2;
            }
            //TODO 藏宝阁确认购买发起请求到服务端
            try {
                OptionsJframe.getOptionsJframe().getOptionsJpanel().
                        showBox(TiShiUtil.CBGBuy, traslationCommodityMainJPane.getName(), "#W确认花费#R" + traslationCommodityMainJPane.getJine().getText() + "#W元来购买这件物品?");
            } catch (Exception ee) {
                ee.printStackTrace();
            }
        }

    }

}
